﻿using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

// Token: 0x0200001E RID: 30
public class OriginSelector : MonoBehaviour
{
	// Token: 0x06000082 RID: 130 RVA: 0x0000DCAD File Offset: 0x0000BEAD
	private void Start()
	{
		this.UpdateInfo();
		PlayerPrefs.SetInt("gameComplete", 1);
		Time.timeScale = 1f;
	}

	// Token: 0x06000083 RID: 131 RVA: 0x0000DCCC File Offset: 0x0000BECC
	private void Update()
	{
		if (Input.GetKeyDown(KeyCode.R))
		{
			SceneManager.LoadScene(SceneManager.GetActiveScene().name);
		}
		if (Input.GetKeyDown(KeyCode.E))
		{
			this.index++;
			if (this.index >= this.origins.Count)
			{
				this.index = 0;
			}
			this.UpdateInfo();
		}
		if (Input.GetKeyDown(KeyCode.Q))
		{
			this.index--;
			if (this.index < 0)
			{
				this.index = this.origins.Count - 1;
			}
			this.UpdateInfo();
		}
		if (!this.fading)
		{
			this.blackImg.color = new Color(0f, 0f, 0f, this.blackImg.color.a - Time.deltaTime * 0.25f);
			if (this.blackImg.color.a < 0.05f)
			{
				this.blackImg.color = new Color(0f, 0f, 0f, 0.05f);
			}
			this.source.volume += Time.deltaTime * 0.125f;
			this.source.volume = Mathf.Clamp(this.source.volume, 0f, 0.5f);
			return;
		}
		this.blackImg.color = new Color(0f, 0f, 0f, this.blackImg.color.a + Time.deltaTime * 0.25f);
		if (this.blackImg.color.a >= 1f)
		{
			this.Go();
			return;
		}
		this.source.volume -= Time.deltaTime * 0.125f;
		this.source.volume = Mathf.Clamp(this.source.volume, 0f, 0.5f);
	}

	// Token: 0x06000084 RID: 132 RVA: 0x0000DEC4 File Offset: 0x0000C0C4
	public void UpdateInfo()
	{
		GameObject gameObject = Resources.Load<GameObject>(this.origins[this.index].objPath);
		this.spawnText.text = this.origins[this.index].name;
		this.desc.text = this.origins[this.index].description;
		this.spawnImage.sprite = gameObject.transform.GetChild(0).GetComponent<SpriteRenderer>().sprite;
		this.spawnImage.SetNativeSize();
		gameObject = Resources.Load<GameObject>(this.origins[this.IntInOriginBounds(this.index - 1)].objPath);
		this.preview1.sprite = gameObject.transform.GetChild(0).GetComponent<SpriteRenderer>().sprite;
		this.preview1.SetNativeSize();
		gameObject = Resources.Load<GameObject>(this.origins[this.IntInOriginBounds(this.index + 1)].objPath);
		this.preview2.sprite = gameObject.transform.GetChild(0).GetComponent<SpriteRenderer>().sprite;
		this.preview2.SetNativeSize();
	}

	// Token: 0x06000085 RID: 133 RVA: 0x0000DFFB File Offset: 0x0000C1FB
	public void FadeOut()
	{
		Sound.Play(Resources.Load<AudioClip>("Sounds/Objective Success"), Vector2.zero, true, false, 1f);
		this.fading = true;
	}

	// Token: 0x06000086 RID: 134 RVA: 0x0000E01F File Offset: 0x0000C21F
	public int IntInOriginBounds(int x)
	{
		if (x >= this.origins.Count)
		{
			x = 0;
		}
		if (x < 0)
		{
			x = this.origins.Count - 1;
		}
		return x;
	}

	// Token: 0x06000087 RID: 135 RVA: 0x0000E048 File Offset: 0x0000C248
	public void Go()
	{
		PlayerPrefs.SetInt("xp", 0);
		PlayerPrefs.SetInt("sp", 0);
		PlayerPrefs.SetInt("xpCap", 50);
		PlayerPrefs.SetString("character", this.origins[this.index].objPath);
		PlayerPrefs.SetInt("up1", 0);
		PlayerPrefs.SetInt("up2", 0);
		PlayerPrefs.SetInt("up3", 0);
		PlayerPrefs.SetInt("up4", 0);
		PlayerPrefs.SetInt("up5", 0);
		PlayerPrefs.SetInt("difficulty", 1);
		PlayerPrefs.SetInt("startWave", 0);
		PlayerPrefs.SetInt("highScore", 1);
		PlayerPrefs.SetInt("hankAdded", 0);
		SceneManager.LoadScene("DarkCorridor");
	}

	// Token: 0x04000156 RID: 342
	public List<Origin> origins = new List<Origin>();

	// Token: 0x04000157 RID: 343
	public TextMeshProUGUI spawnText;

	// Token: 0x04000158 RID: 344
	public TextMeshProUGUI desc;

	// Token: 0x04000159 RID: 345
	public Image spawnImage;

	// Token: 0x0400015A RID: 346
	public Image preview1;

	// Token: 0x0400015B RID: 347
	public Image preview2;

	// Token: 0x0400015C RID: 348
	public int index;

	// Token: 0x0400015D RID: 349
	public AudioSource source;

	// Token: 0x0400015E RID: 350
	public Image blackImg;

	// Token: 0x0400015F RID: 351
	private bool fading;
}
